package com.wc.codeforces.思维.Game_of_Mathletes;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2025/5/4 19:49
 * @description
 * https://codeforces.com/contest/2060/problem/C
 */
public class Main {
    /**
     * 思路：
     * A 选择一个, 如果可以匹配, 一定会选择匹配的
     *            如果不可以匹配, 那我们选择一个同样不可以匹配的
     *            如果不存在不可以匹配的, 那就影响可以匹配的, 那也就同时一直会影响, 但是也只是影响不重复匹配的, 所以可结题
     */
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 400010;
    static int[] num = new int[N];
    static int n, k;

    public static void main(String[] args) {
        int T = sc.nextInt();
        while (T-- > 0) {
            n = sc.nextInt();
            k = sc.nextInt();
            // k - i 可能会 > n, 所以要多初始化一点
            Arrays.fill(num, 1, 2 * n + 1, 0);
            for (int i = 1; i <= n; i++) {
                int x = sc.nextInt();
                num[x] ++;
            }
            int res = 0, one = 0;
            for (int i = 1; i <= n; i++) {
                int t = 0;
                // 保证只匹配一次
                if (k - i > i) t = Math.min(num[i], num[Math.max(0, k - i)]);
                // 匹配自己
                if (k - i == i) t =  num[i] / 2;

                // 看下有多少个不同的可匹配的队伍
                if (t > 0) one++;
                res += t;
            }
            int rp = n - res * 2;
            // 如果不匹配的多了一个的话, 就影响不同可匹配的队伍
            if ((rp & 1) == 1) res -= one;

            out.println(res);
        }
        out.flush();
    }
}


class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}

